#!/bin/sh
#tailJarPath和sourcePath参数在jenkins中配置，方便切换部署环境
#tailJarPath=/home/lcc/jar/base-frame
#sourcePath=/home/lcc/.jenkins/workspace/DeployTailWebFrame

stopTailJar(){
	pid=`ps -wef | grep tailWebFrame.jar | grep -v grep | awk '{print $2}'`
	if test -z "${pid}"
	then
	    echo "服务未启动"
	else
	    kill -9 ${pid}
	    echo "已杀死服务进程,进程号为${pid}"
	fi
}

createBakDir(){
	if [ ! -d $bakdirpath ]; then
		mkdir -p $bakdirpath
		echo "创建${bakdirpath}文件夹"
	else
		echo "${bakdirpath}已存在"
	fi
}

mvn clean package

if (( $? ))
then
	echo "mvn package failed"
	exit 1
else
	echo "mvn package success"
fi

stopTailJar

createBakDir

cp ${tailJarPath}/tailWebFrame.jar ${bakdirpath}/tailWebFrame.jar`date +%Y%m%d%H%M%S`
echo "备份当前jar包到${bakdirpath}目录"

cp ${sourcePath}/target/tailWebFrame.jar ${tailJarPath}/tailWebFrame.jar
echo "迁移最新编译的jar包到运行目录"

cd ${tailJarPath}
nohup java -jar tailWebFrame.jar > /dev/null &
echo "启动完成"
